<?php 
session_start();
unset($_SESSION['openid']);
 
 exit;
$header = array(
		'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
		'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
		'Accept-Encoding: gzip, deflate',);
$url='http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTL2mibdjbTeYSIJrCaFn4jjaiaEtyzEl4LQzP0ZZsAU3ibKxFlhdBHWp3GmmvRIPMTLYB5iaGhVU0DG5Q/132';
$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);$data = curl_exec($curl);$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);curl_close($curl);
if ($code == 200) {//把URL格式的图片转成base64_encode格式的！
	$imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
}
$img_content=$imgBase64Code;//图片内容
//echo $img_content;exit;
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
{
	$type = $result[2];//得到图片类型png?jpg?gif?
	$new_file = "./upload/cs.{$type}";
	if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $img_content))))
	{  echo '新文件保存成功：', $new_file; }}
	
	
exit;



function yuan_img($imgpath = './tx.jpg') {
	$ext     = pathinfo($imgpath);
	$src_img = null;
	switch ($ext['extension']) {
		case 'jpg':
			$src_img = imagecreatefromjpeg($imgpath);
			break;
		case 'png':
			$src_img = imagecreatefrompng($imgpath);
			break;
	}
	$wh  = getimagesize($imgpath);
	$w   = $wh[0];
	$h   = $wh[1];
	$w   = min($w, $h);
	$h   = $w;
	$img = imagecreatetruecolor($w, $h);
	//这一句一定要有
	imagesavealpha($img, true);
	//拾取一个完全透明的颜色,最后一个参数127为全透明
	$bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
	imagefill($img, 0, 0, $bg);
	$r   = $w / 2; //圆半径
	$y_x = $r; //圆心X坐标
	$y_y = $r; //圆心Y坐标
	for ($x = 0; $x < $w; $x++) {
		for ($y = 0; $y < $h; $y++) {
			$rgbColor = imagecolorat($src_img, $x, $y);
			if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
				imagesetpixel($img, $x, $y, $rgbColor);
			}
		}
	}
	return $img;
}
header("content-type:image/jpg");
$imgg = yuan_img('132.jpg');
imagepng($imgg);
imagedestroy($imgg);
